package com.example.demo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.dto.User.UserQueryRequest;
import com.example.demo.entity.User;
import com.example.demo.service.UserService;
import com.example.demo.dao.UserMapper;
import org.springframework.stereotype.Service;

/**
* @author darling
* @description 针对表【user】的数据库操作Service实现
* @createDate 2025-05-01 23:54:03
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService{

    @Override
    public QueryWrapper<User> getQueryWrapper(UserQueryRequest userQueryRequest) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        Integer id = userQueryRequest.getId();
        String name = userQueryRequest.getName();
        String password = userQueryRequest.getPassword();
        String phone = userQueryRequest.getPhone();
        String sortField = userQueryRequest.getSortField();
        String sortOrder = userQueryRequest.getSortOrder();
        //精确查询
        queryWrapper.eq(ObjectUtils.isNotEmpty(id), "id", id);
        queryWrapper.eq(ObjectUtils.isNotEmpty(password), "password", password);

        //模糊查询
        queryWrapper.like(ObjectUtils.isNotEmpty(phone), "phone", phone);
        queryWrapper.like(ObjectUtils.isNotEmpty(name), "name", name);
        //排序规则
        queryWrapper.orderBy(ObjectUtils.isNotEmpty(sortField), sortOrder.equals("ascend"), sortField);
        return queryWrapper;
    }
}




